const {adminsModel}=require('./models/adminsModel');
module.exports.getAdmins=async function(params){
    const total=await adminsModel.countDocuments();
    const pages =Math.ceil(total/params.pageSize);
    const admins=await adminsModel.find().limit(params.pageSize*1).skip((params.currentPage-1)*params.pageSize);
    console.log('Dao',params);
    return {total,pages,admins}
};
module.exports.searchAdmins=async (params)=>{
   
    const total=await adminsModel.countDocuments({names:{$regex:params.value,$options:'$i'}});
    const pages =Math.ceil(total/params.pageSize);
    const admins= await adminsModel.find({names:{$regex:params.value,$options:'$i'}}).limit(params.pageSize*1).skip((params.currentPage-1)*params.pageSize);
    
    return{total,pages,admins}
 };
 module.exports.getAdminsById=async function(params){
    return await adminsModel.find({_id:params})
};
module.exports.updateAdmins=async params=>{
    
    return await adminsModel.updateOne({_id:params.adminsData._id},params.adminsData);
    
 };
 module.exports.deleteAdmins=async params=>{
    return await adminsModel.deleteOne({_id:params.adminsId});
 };
 module.exports.addAdmins=async params=>{
    return await adminsModel.create(params);
 };
